package com.isdepci.project.eleLoad.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.eleLoad.domain.AMachineryInformation;
import com.isdepci.project.eleLoad.service.IAMachineryInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 机械信息Controller
 *
 * @author isdepci
 * @date 2025-02-26
 */
@RestController
@RequestMapping("/eleLoad/machinery")
public class AMachineryInformationController extends BaseController
{
    @Autowired
    private IAMachineryInformationService aMachineryInformationService;

    /**
     * 查询机械信息列表
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:machinery:list')")
    @GetMapping("/list")
    public TableDataInfo list(AMachineryInformation aMachineryInformation)
    {
        startPage();
        List<AMachineryInformation> list = aMachineryInformationService.selectAMachineryInformationList(aMachineryInformation);
        return getDataTable(list);
    }

    /**
     * 导出机械信息列表
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:machinery:export')")
    @Log(title = "机械信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AMachineryInformation aMachineryInformation)
    {
        List<AMachineryInformation> list = aMachineryInformationService.selectAMachineryInformationList(aMachineryInformation);
        ExcelUtil<AMachineryInformation> util = new ExcelUtil<AMachineryInformation>(AMachineryInformation.class);
        return util.exportExcel(list, "machinery");
    }

    /**
     * 获取机械信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:machinery:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(aMachineryInformationService.selectAMachineryInformationById(id));
    }

    /**
     * 新增机械信息
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:machinery:add')")
    @Log(title = "机械信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AMachineryInformation aMachineryInformation)
    {
        return toAjax(aMachineryInformationService.insertAMachineryInformation(aMachineryInformation));
    }

    /**
     * 修改机械信息
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:machinery:edit')")
    @Log(title = "机械信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AMachineryInformation aMachineryInformation)
    {
        return toAjax(aMachineryInformationService.updateAMachineryInformation(aMachineryInformation));
    }

    /**
     * 删除机械信息
     */
    @PreAuthorize("@ss.hasPermi('eleLoad:machinery:remove')")
    @Log(title = "机械信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aMachineryInformationService.deleteAMachineryInformationByIds(ids));
    }
}
